const express = require('express')
const router = express.Router()
const fs = require('fs')



// 选择我的兴趣技能
// 1.获取兴趣列表
router.get('/avocation/avocations/rec/user', (req, res) => {
    const { pageSize, pageNum } = req.query
    const resData = fs.readFileSync('data/avocations.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).content.splice(pageSize * pageNum, pageSize * (pageNum + 1))
    res.json({
        code: 20000,
        data: {
            content: data,
            number: 2,
            numberOfElements: 22,
            size: pageSize,
            sort: null,
            statistics: null,
            totalElements: 1829,
            totalPages: 92,
            useOffset: false
        }
    })
})
// 2.兴趣列表_已选的
router.get('/userCenter/users/me', (req, res) => {
    const data = fs.readFileSync('data/userCenter.json', { encoding: 'utf8' })
    res.json({ code: 20000, data: JSON.parse(data), value: '获取数据成功~' })
})
// 3.兴趣列表_关键字搜索
router.get('/avocation/avocations/search/findByName', (req, res) => {
    const { name } = req.query
    const resData = fs.readFileSync('data/avocation_search.json', { encoding: 'utf8' })
    const data = JSON.parse(resData).find(item => item.name === name)
    if (!data) return res.json({ code: 20000, data: { content: null }, value: '暂无数据~' })
    res.json({ code: 20000, data: { content: data }, value: '获取数据成功~' })
})


export default router